package game

import (
	"context"
	"database/sql"
	"fmt"
	"github.com/zeromicro/go-zero/core/stores/cache"
	"github.com/zeromicro/go-zero/core/stores/sqlx"
)

var _ OrderStatModel = (*customOrderStatModel)(nil)

type (
	// OrderStatModel is an interface to be customized, add more methods here,
	// and implement the added methods in customOrderStatModel.
	OrderStatModel interface {
		orderStatModel
		UpdateTrans(ctx context.Context, tx sqlx.Session, providerId, lastIdx int64) (sql.Result, error)
	}

	customOrderStatModel struct {
		*defaultOrderStatModel
	}
)

// NewOrderStatModel returns a model for the database table.
func NewOrderStatModel(conn sqlx.SqlConn, c cache.CacheConf, opts ...cache.Option) OrderStatModel {
	return &customOrderStatModel{
		defaultOrderStatModel: newOrderStatModel(conn, c, opts...),
	}
}

func (m *customOrderStatModel) UpdateTrans(ctx context.Context, tx sqlx.Session, providerId, lastIdx int64) (sql.Result, error) {
	q := fmt.Sprintf(`update %s set last_idx = ? where provider_id = ?`, m.table)
	return tx.ExecCtx(ctx, q, lastIdx, providerId)
}
